import { getPixi } from '@/store/modules/usePixiStore'
import useMainStore from '@/store/modules/useMainStore'
import useSearchStore from '@/store/modules/useSearchStore'
import newCard from './newCard'
import { useWindowSize } from '@vueuse/core'
import useCardsStore from '@/store/modules/useCardsStroe'

// 卡牌参数
export default async () => {
  const mainStore = useMainStore()
  const searchStore = useSearchStore()
  const cardsStore = useCardsStore()
  const { scale } = mainStore.getAppAttr
  const { width, height } = useWindowSize()
  const bottomWidth = (width.value / scale - 96) * 0.88 - 453 * 0.83 + 48
  const bottomHeight = height.value / scale - 114 - 30
  const cardSetsContainer = getPixi('cardSets')
  cardSetsContainer.removeChildren() // 清空卡牌
  cardsStore[searchStore.from].forEach(async (data, index) => {
    const card = await newCard(data)
    const x = index % 4
    const y = Math.floor(index / 4)
    card.scale.set(0.7)
    card.position.set(bottomWidth * (x / 4 + 0.125), bottomHeight * (y / 2 + 0.25))
    cardSetsContainer.addChild(card)
  })
}
